package com.gxkj.projects.myshopx.controllers.demo;

import com.alibaba.fastjson.JSON;
import com.gxkj.projects.myshopx.controllers.AdminIndexController;
import com.gxkj.projects.myshopx.dto.ReturnData;
import com.gxkj.projects.myshopx.entitys.Goods;
import com.gxkj.projects.myshopx.enums.ErrorCodeEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping("/demo/group")
public class DemoGroupController {
    Logger LOG = LoggerFactory.getLogger(DemoGroupController.class);

    @RequestMapping(value="",method= RequestMethod.GET)
    public String index(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap){
        return "demo/demo_group";
    }

    @RequestMapping(value="doadd",method= RequestMethod.POST)
    @ResponseBody
    public ReturnData<Boolean> doAdd(
            @RequestParam(value="img_url[]" ,required = false) CommonsMultipartFile[] img_urls,
            @RequestParam(value = "img_file[]",required = false)String[] img_files,
            @RequestParam(value ="img_desc[]" ,required = false)String[] img_descs,
            HttpServletRequest request, HttpServletResponse response, ModelMap modelMap){
        ReturnData<Boolean> returnData = new ReturnData<Boolean>();
        LOG.info("img_urls.length="+img_urls.length);
        LOG.info("img_files.length="+img_files.length);
        LOG.info("img_descs.length="+img_descs.length);
        returnData.setEntity(new Boolean(true));
        returnData.setStatusCode(ErrorCodeEnum.NORMAL.getCode());
        return returnData;
    }

    @RequestMapping(value="doadd2",method= RequestMethod.POST)
    @ResponseBody
    public ReturnData<Boolean> doAdd2(
            @RequestParam(value = "old_img_desc[]",required = false)String[] old_img_desc,
            @RequestParam(value = "old_img_id[]",required = false)String[] old_img_id,
            HttpServletRequest request, HttpServletResponse response, ModelMap modelMap){
        ReturnData<Boolean> returnData = new ReturnData<Boolean>();
        LOG.info("old_img_desc.length="+old_img_desc.length+";old_img_desc="+ JSON.toJSONString(old_img_desc));
        LOG.info("old_img_id.length="+old_img_id.length+";old_img_id="+ JSON.toJSONString(old_img_id));

        returnData.setEntity(new Boolean(true));
        returnData.setStatusCode(ErrorCodeEnum.NORMAL.getCode());

        return returnData;
    }



}
